package conf

import (
	"fmt"
	"github.com/spf13/viper"
)

var (
	Cfg *MyConfig  //全局的配置
)

type MyConfig struct {
	Kafka *Kafka `yaml:"kafka"`
	Taillog *Taillog `yaml:"taillog"`
}

type Kafka struct {
	Addr string `yaml:"addr"`
	Topic string `yaml:"topic"`
}

type Taillog struct {
	Path string `yaml:"path"`
}
func Init(){
	viper.SetConfigType("yaml")
	viper.SetConfigFile("./conf/app.yml")
	err:= viper.ReadInConfig()
	if err != nil {
		fmt.Println("init yaml fail",err)
	}
	err = viper.Unmarshal(&Cfg)
	if err != nil {
		fmt.Println("解析yml错误")
	}
	fmt.Println("init yaml success")
	return
}